<html>
<body>
<script src="/js-test-resources/js-test.js"></script>
<script>
(function() {
description('Make two XHRs for the resource which is already cached.');
window.jsTestIsAsync = true;
var url = 'resources/get.txt';
function get(xhr, async) {
    return new Promise(function(resolve, reject) {
        setTimeout(function() {
            xhr.onreadystatechange = function() {
                if (xhr.readyState === xhr.DONE) {
                    if (xhr.status === 200) {
                        resolve(xhr.responseText);
                    } else {
                        reject(xhr.status);
                    }
                }
            };
            xhr.open('GET', url, async);
            xhr.send();
        }, 0);
    });
}
var xhr1 = new XMLHttpRequest();
var xhr2 = new XMLHttpRequest();

Promise.resolve().then(function() {
    var async = get(xhr1, true);
    var sync = get(xhr2, false);
    return Promise.all([sync, async]);
}).then(function(results) {
    window.result1 = results[0];
    window.result2 = results[1];
    shouldBeEqualToString('result1', 'PASS');
    shouldBeEqualToString('result2', 'PASS');
    if (localStorage.reload) {
        testPassed('DONE');
        finishJSTest();
    } else {
        localStorage.reload = true;
        location.reload(true);
    }
}, function(e) {
    testFailed(e);
    finishJSTest();
});
}());

</script>
</body>
</html>
